/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-11-09
 * Time: 9:06
 */
class Singleton1 {
    private  static volatile Singleton1 instance = null;

    private Singleton1(){}

    public static Singleton1 getInstance(){
        if (instance == null){
            synchronized (Singleton1.class){
                if (instance == null){
                    return new Singleton1();
                }
            }
        }
        return instance;
    }

    //1.双重if 2.synchronized加锁 3.volatile 防止指令重排序
}

//单例模式的 懒汉模式
public class Demo2 {
    public static void main(String[] args) {
        Singleton1 instance = Singleton1.getInstance();
    }
}
